local yongsi = fk.CreateSkill{
  name = "mod__yongsi",
  frequency = Skill.Compulsory,
}
local yongsi_ = {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.DrawNCards then
        return true
      else
        if player.phase == Player.Play then
          local n = 0
          for _, e in ipairs(player.room.logic:getActualDamageEvents(999, function(e) return e.data[1].from == player end)) do
            local damage = e.data[1]
            n = n + damage.damage
          end
          return (n == 0 and player:getHandcardNum() < player:getMaxCards()) or n > 1
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DrawNCards then
      local kingdoms = {}
      for _, p in ipairs(room.alive_players) do
        table.insertIfNeed(kingdoms, p.kingdom)
      end
      data.n = data.n + #kingdoms
    else
      local n = 0
      for _, e in ipairs(room.logic:getActualDamageEvents(999, function(e) return e.data[1].from == player end)) do
        local damage = e.data[1]
        n = n + damage.damage
      end
      if n == 0 and player:getHandcardNum() < player:getMaxCards() then
        player:drawCards(player:getMaxCards() - player:getHandcardNum(), self.name)
      elseif n > 1 then
        local kingdoms = {}
        for _, p in ipairs(room.alive_players) do
          table.insertIfNeed(kingdoms, p.kingdom)
        end
        room:askForDiscard(player, #kingdoms, #kingdoms, true, self.name, false, nil, "yongsi_ask:::"..#kingdoms)
      end
    end
  end,
}
yongsi:addEffect(fk.DrawNCards, yongsi_)
yongsi:addEffect(fk.EventPhaseEnd, yongsi_)
return yongsi